Vue.component('filelist', {
  template: '<div class="grid-content" id="fdata">' +
    '<el-table :data="fileData" class="w-tablesub">'+
	    '<el-table-column prop="rowrec" label="序号" width="100">'+
	    '</el-table-column>'+
	    '<el-table-column label="文件名" class="w-textsub">'+
	     '<template slot-scope="scope">'+
	         '<el-popover trigger="hover" placement="top-start">'+
	             '<p class="w-tablepop">{{ scope.row.file_name }}</p>'+
	             '<div slot="reference" >'+
	                '{{ scope.row.file_name }}'+
	             '</div>'+		                           
	         '</el-popover>'+
           '</template>'+
	    '</el-table-column>'+
	    '<el-table-column  label="文件路径" width="300" class="w-textsub">'+
	         '<template slot-scope="scope">'+
	             '<el-popover trigger="hover" placement="top-start">'+
	                 '<p class="w-tablepop">{{ scope.row.file_path }}</p>'+
	                 '<div slot="reference" >'+
	                    '{{ scope.row.file_path }}'+
	                 '</div>'+		                           
	             '</el-popover>'+
	         '</template>'+
		'</el-table-column>'+
		'<el-table-column prop="upload_date" label="上传时间">'+
	    '</el-table-column>'+                               
	    '<el-table-column label="操作">'+
		    '<template slot-scope="scope">'+
		    '<i class="el-icon-download" title="下载" style="cursor:pointer; font-size:18px;" @click="download(scope.row)"></i>&nbsp;'+
		    '<i class="el-icon-delete"  title="删除" style="cursor:pointer;" @click="del(scope.row)" v-if="deletable"></i>'+
	        '</template>'+
        '</el-table-column>'+
    '</el-table>'+
    '<div class="block mt10">'+
	    '<el-pagination @size-change="handleSizeChange"'+
	        '@current-change="handleCurrentChange"'+
	        ':current-page="currentPageNbr" :page-sizes="pageSizes"'+
	        ':page-size="pageSize" class="w-tc"'+
	        'layout="total, sizes, prev, pager, next, jumper"'+
	        ':total="totalRecords"> </el-pagination>'+
     '</div>'+
   '</div>',

  props: {
	args: {
		type: Object
    },
//    deletable: Boolean,
    deletable: {
    	type: Boolean,
		default: false
	},
  },  
  data: function(){
    return {
    	msgId:'',
    	fileNo:'',
    	fileData:[],    
    	currentPageNbr: config.currentPageNbr,
        pageSizes: config.pageSizes,
        pageSize: config.defaultpageSize,
        totalRecords: 0,          
    }
  },
  beforeDestory: function(){
	    console.log("destory");
  },
  mounted: function () {
	 this.initData();
  },
  methods: {
    initData:function(){
    	
    }, 
    refresh:function(){
    	this.currentPageNbr=config.currentPageNbr;
    	this.pageSize = config.defaultpageSize;
    	this.onSearch();    	
    },
    download:function(row){
    	var filename = row.file_name;
		var filepath =row.file_path;    
		var form="<form id='download' action='../../pub/attach/download' method='post'>";
		form +="<input type='hidden' name='filename'  value='"+filename+"' />";
		form +="<input type='hidden' name='filepath'  value='"+filepath+"' />";
		form +="</form>";
		$("#fdata").append(form);
		$("#download").submit();
		$("#download").remove();
    },
    del:function(row){
    	var that =this;
    	var reqData = {	
    		"fileId":row.file_id,
    		"filePath":row.file_path
    	};
    	this.$confirm('确定删除文件-'+row.file_name+'?', '提示', {
	            confirmButtonText: '确定',
	            cancelButtonText: '取消',
	            type: 'warning'
    	}).then(() => {
    		tools.ajaxRequestAsyncEx("pub/attach/fileDelete", reqData, function(data){
        		if (data.respCode == "0") {
        			that.$message({
    		            showClose: true,
    		            type: 'success',
    		            message: "删除成功"
    		        });  
        			that.refresh();
         	   } else {
         	       that.showError(data.respDesc);      
         	   }
        	});
	    }).catch(() => {     
	        	
	    });
    	
    },
    onSearch:function(){
    	this.msgId = this.args.msgId;
    	this.fileNo = this.args.fileNo;
    	var that =this;
    	var jsonStr = {	
    		"fileNo":this.fileNo
    	};
    	var reqData ={
    	  "jsonStr": JSON.stringify(jsonStr),
    	  "currentPageNbr" : this.currentPageNbr,
    	  "pageSize": this.pageSize
    	};
    	tools.ajaxRequestAsyncEx("pub/attach/uploadFileList", reqData, function(data){
    	   if (data.respCode == "0") {
    	       that.fileData = data.list;
    	       that.totalRecords = data.page.totalRecords;       
    	   } else {
    	       that.fileData = [];
    	       that.totalRecords =0;
    	       that.currentPageNbr=1;
    	       that.showError(data.respDesc);      
    	   }
    	});
    	
    },
    
    handleSizeChange:function(pageSize){
        this.pageSize = pageSize;
        this.currentPageNbr = 1;
        this.onSearch();
    },

    handleCurrentChange:function(currentPageNbr){
      this.currentPageNbr = currentPageNbr;
      this.onSearch();
    },
    
    showError: function(info){
        var i = (info==undefined?"加载数据错误":info);
        this.$alert(i, '系统错误', {
             confirmButtonText: '确定'
        }); 
    },
    
  },
  
  watch:{	  
//      currentPageNbr : function() {
//          this.onSearch();
//      },
//        
//      pageSize : function() {
//    	  if(this.currentPageNbr=="1"){
//    		  this.onSearch();
//    	  }else{
//    		  this.currentPageNbr=="1";
//    	  }          
//      },
  }
  
}) 
